/*     */ package dm.sql;
/*     */ 
/*     */ import dm.jdbc.dataConvertion.Convertion;
/*     */ import dm.jdbc.dbaccess.DBError;
/*     */ import dm.jdbc.util.StringUtil;
/*     */ import java.sql.SQLException;
/*     */ 
/*     */ 
/*     */ public class DmdbTimeZone
/*     */   implements Cloneable
/*     */ {
/*  12 */   byte[] value = new byte[12];
/*  13 */   byte[] value_timestamp_tz = new byte[9];
/*     */   int ctype;
/*     */   String str;
/*  16 */   int prec = 0;
/*     */   
/*     */   public int getTzType() {
/*  19 */     if (this.ctype == 1) {
/*  20 */       return 22;
/*     */     }
/*  22 */     return 23;
/*     */   }
/*     */   
/*     */   public int getScale() {
/*  26 */     return this.prec;
/*     */   }
/*     */   
/*     */   public byte[] getValueBytes() {
/*  30 */     return this.value;
/*     */   }
/*     */   
/*     */   public final Object clone() {
/*  34 */     DmdbTimeZone o = null;
/*     */     try {
/*  36 */       o = (DmdbTimeZone)super.clone();
/*  37 */       if (this.value != null)
/*  38 */         o.value = ((byte[])this.value.clone());
/*  39 */       if (this.value_timestamp_tz != null)
/*  40 */         o.value_timestamp_tz = ((byte[])this.value_timestamp_tz.clone());
/*     */     } catch (CloneNotSupportedException e) {
/*  42 */       e.printStackTrace();
/*     */     }
/*  44 */     return o;
/*     */   }
/*     */   
/*     */   public DmdbTimeZone(String str, int ctype, short defaultTz) throws SQLException
/*     */   {
/*  49 */     this.str = str;
/*  50 */     this.ctype = ctype;
/*  51 */     this.value = getValueFromTZ(defaultTz);
/*     */   }
/*     */   
/*     */   public DmdbTimeZone(byte[] dt, int prec, int ctype) {
/*  55 */     this.value = dt;
/*  56 */     this.ctype = ctype;
/*  57 */     this.prec = prec;
/*     */   }
/*     */   
/*     */   public int hashCode() {
/*  61 */     return getStrFromTZ().hashCode();
/*     */   }
/*     */   
/*     */   public boolean equals(Object o) {
/*  65 */     if (o == null) {
/*  66 */       return false;
/*     */     }
/*  68 */     if (!(o instanceof DmdbTimeZone)) {
/*  69 */       return false;
/*     */     }
/*  71 */     DmdbTimeZone tm = (DmdbTimeZone)o;
/*     */     
/*  73 */     byte[] bs = tm.value;
/*  74 */     for (int i = 0; i < 12; i++) {
/*  75 */       if (this.value[i] != bs[i]) {
/*  76 */         return false;
/*     */       }
/*     */     }
/*  79 */     return true;
/*     */   }
/*     */   
/*     */   public String getStrFromTZ() {
/*  83 */     int year = 0;
/*  84 */     short month = 0;
/*  85 */     short day = 0;
/*  86 */     short hour = 0;
/*  87 */     short min = 0;
/*  88 */     short sec = 0;
/*  89 */     int msec = 0;
/*  90 */     int tz = 0;
/*  91 */     String str = "";
/*     */     
/*  93 */     if (this.ctype == 1) {
/*  94 */       hour = (short)(this.value[0] & 0x1F);
/*  95 */       min = (short)((this.value[0] >> 5 & 0x7) + ((this.value[1] & 0x7) << 3));
/*  96 */       sec = (short)((this.value[1] >> 3 & 0x1F) + ((this.value[2] & 0x1) << 5));
/*  97 */       msec = (this.value[2] >> 1 & 0x7F) + ((this.value[3] & 0xFF) << 7) + ((this.value[4] & 0x1F) << 15);
/*  98 */       tz = Convertion.getShort(this.value, 5);
/*  99 */     } else if (this.ctype == 2) {
/* 100 */       year = Convertion.getShort(this.value, 0);
/* 101 */       year &= 0x7FFF;
/* 102 */       if (year > 9999) {
/* 103 */         year = (short)((short)year | 0x8000);
/*     */       }
/* 105 */       month = (short)((this.value[1] >> 7 & 0x1) + ((this.value[2] & 0x7) << 1));
/* 106 */       day = (short)((this.value[2] & 0xF8) >> 3 & 0x1F);
/* 107 */       hour = (short)(this.value[3] & 0x1F);
/* 108 */       min = (short)((this.value[3] >> 5 & 0x7) + ((this.value[4] & 0x7) << 3));
/* 109 */       sec = (short)((this.value[4] >> 3 & 0x1F) + ((this.value[5] & 0x1) << 5));
/* 110 */       msec = (this.value[5] >> 1 & 0x7F) + ((this.value[6] & 0xFF) << 7) + ((this.value[7] & 0x1F) << 15);
/* 111 */       tz = Convertion.getShort(this.value, 8);
/*     */     }
/* 113 */     String h = hour;
/* 114 */     String m = min;
/* 115 */     String s = sec;
/* 116 */     String n = msec;
/*     */     
/* 118 */     if (h.length() < 2) {
/* 119 */       h = "0" + h;
/*     */     }
/*     */     
/* 122 */     if (m.length() < 2) {
/* 123 */       m = "0" + m;
/*     */     }
/*     */     
/* 126 */     if (s.length() < 2) {
/* 127 */       s = "0" + s;
/*     */     }
/*     */     
/* 130 */     if (this.prec > 0) {
/* 131 */       int nlen = n.length();
/* 132 */       if (nlen < 6) {
/* 133 */         for (int i = 0; i < 6 - nlen; i++)
/* 134 */           n = "0" + n;
/*     */       }
/* 136 */       if (n.length() > this.prec) {
/* 137 */         n = n.substring(0, this.prec);
/*     */       }
/*     */     }
/*     */     
/* 141 */     if (this.ctype == 2) {
/* 142 */       str = str + year;
/*     */       
/* 144 */       String mon = month;
/* 145 */       if (mon.length() < 2) {
/* 146 */         mon = "0" + mon;
/*     */       }
/* 148 */       String d = day;
/* 149 */       if (d.length() < 2) {
/* 150 */         d = "0" + d;
/*     */       }
/* 152 */       str = str + "-" + mon + "-" + d + " ";
/*     */     }
/*     */     
/* 155 */     if (this.prec == 0) {
/* 156 */       str = str + h + ":" + m + ":" + s;
/*     */     } else {
/* 158 */       str = str + h + ":" + m + ":" + s + "." + n;
/*     */     }
/* 160 */     if (tz >= 0) {
/* 161 */       str = str + " +";
/*     */     } else {
/* 163 */       str = str + " -";
/*     */     }
/* 165 */     int tz_hour = Math.abs(tz / 60);
/* 166 */     int tz_min = Math.abs(tz % 60);
/*     */     
/* 168 */     String tz_hour_s = tz_hour;
/* 169 */     String tz_min_s = tz_min;
/* 170 */     if (tz_hour_s.length() < 2) {
/* 171 */       tz_hour_s = "0" + tz_hour_s;
/*     */     }
/* 173 */     if (tz_min_s.length() < 2) {
/* 174 */       tz_min_s = "0" + tz_min_s;
/*     */     }
/* 176 */     str = str + tz_hour_s + ":" + tz_min_s;
/*     */     
/* 178 */     return str;
/*     */   }
/*     */   
/*     */   public byte[] getValueFromTZ(short tz)
/*     */     throws SQLException
/*     */   {
/* 184 */     byte tz_min = 0;
/*     */     
/* 186 */     byte[] dt_tz = new byte[12];
/*     */     
/* 188 */     if (this.ctype == 1) {
/* 189 */       dt_tz[0] = 0;
/* 190 */       dt_tz[1] = 0;
/* 191 */       dt_tz[2] = 0;
/* 192 */       dt_tz[3] = 0;
/*     */     }
/*     */     
/* 195 */     if (this.ctype == 2) {
/* 196 */       int sign = 0;
/* 197 */       if (this.str.startsWith("-")) {
/* 198 */         this.str = this.str.substring(1).trim();
/* 199 */         sign = 1;
/* 200 */       } else if (this.str.startsWith("+")) {
/* 201 */         this.str = this.str.substring(1).trim();
/* 202 */         sign = 0;
/*     */       }
/*     */       
/* 205 */       String[] subStr = StringUtil.split(this.str, "-: .");
/* 206 */       short year = Short.parseShort(subStr[0]);
/* 207 */       if (sign == 1) {
/* 208 */         year = (short)(0 - year);
/*     */       }
/* 210 */       byte month = Byte.parseByte(subStr[1]);
/* 211 */       byte day = Byte.parseByte(subStr[2]);
/* 212 */       byte[] y = Convertion.shortToByteArray(year);
/* 213 */       dt_tz[0] = y[0];
/* 214 */       dt_tz[1] = y[1];
/* 215 */       dt_tz[2] = month;
/* 216 */       dt_tz[3] = day;
/*     */       
/* 218 */       int ind = this.str.indexOf(" ");
/* 219 */       this.str = this.str.substring(ind + 1, this.str.length()).trim();
/*     */     }
/*     */     
/* 222 */     String[] subs = StringUtil.split(this.str, ":. +-");
/* 223 */     byte hour = Byte.parseByte(subs[0]);
/* 224 */     byte minute = Byte.parseByte(subs[1]);
/* 225 */     byte sec = Byte.parseByte(subs[2]);
/* 226 */     dt_tz[4] = hour;
/* 227 */     dt_tz[5] = minute;
/* 228 */     dt_tz[6] = sec;
/*     */     int i;
/* 230 */     int i; if (this.str.indexOf(".") != -1)
/*     */     {
/* 232 */       StringBuffer strNano = new StringBuffer(10);
/* 233 */       strNano.append("0");
/* 234 */       strNano.append(".");
/* 235 */       strNano.append(subs[3]);
/* 236 */       double d_v = Double.valueOf(strNano.toString()).doubleValue();
/* 237 */       int nano = (int)(d_v * 1000000.0D);
/* 238 */       byte[] msec = Convertion.IntToByteArray(nano);
/* 239 */       System.arraycopy(msec, 0, dt_tz, 7, 3);
/*     */       
/* 241 */       i = 4;
/*     */     } else {
/* 243 */       dt_tz[7] = 0;
/* 244 */       dt_tz[8] = 0;
/* 245 */       dt_tz[9] = 0;
/*     */       
/* 247 */       i = 3;
/*     */     }
/*     */     
/* 250 */     while ((subs.length > i) && (subs[i].equals(""))) {
/* 251 */       i++;
/*     */     }
/*     */     
/* 254 */     if (subs.length > i) { byte tz_hour;
/* 255 */       if (this.str.indexOf("-") != -1) {
/* 256 */         byte tz_hour = Byte.parseByte("-" + subs[(i++)]);
/* 257 */         if (subs.length > i) {
/* 258 */           tz_min = Byte.parseByte("-" + subs[(i++)]);
/*     */         }
/*     */       } else {
/* 261 */         tz_hour = Byte.parseByte(subs[(i++)]);
/* 262 */         if (subs.length > i) {
/* 263 */           tz_min = Byte.parseByte(subs[(i++)]);
/*     */         }
/*     */       }
/* 266 */       tz = (short)(tz_hour * 60 + tz_min);
/*     */     }
/*     */     
/* 269 */     if ((tz > 780) || (tz < 64816)) {
/* 270 */       DBError.throwSQLException(6014);
/*     */     }
/* 272 */     byte[] tz_bs = Convertion.shortToByteArray(tz);
/* 273 */     dt_tz[10] = tz_bs[0];
/* 274 */     dt_tz[11] = tz_bs[1];
/*     */     
/* 276 */     return dt_tz;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static byte[] timeZoneEncodeFast(byte[] dt)
/*     */   {
/* 285 */     byte[] ret = new byte[7];
/*     */     
/* 287 */     byte hour = dt[4];
/* 288 */     byte min = dt[5];
/* 289 */     byte sec = dt[6];
/* 290 */     int msec = (0xFF & dt[7]) + ((dt[8] & 0xFF) << 8) + (
/* 291 */       (dt[9] & 0xFF) << 16);
/*     */     
/*     */ 
/* 294 */     ret[0] = ((byte)(hour | (min & 0x7) << 5));
/*     */     
/*     */ 
/* 297 */     ret[1] = ((byte)((min & 0x38) >> 3 | (sec & 0x1F) << 3));
/*     */     
/*     */ 
/* 300 */     ret[2] = ((byte)((sec & 0x20) >> 5 | (msec & 0x7F) << 1));
/*     */     
/*     */ 
/* 303 */     ret[3] = ((byte)(msec >> 7 & 0xFF));
/*     */     
/*     */ 
/* 306 */     ret[4] = ((byte)(msec >> 15 & 0xFF));
/*     */     
/*     */ 
/* 309 */     System.arraycopy(dt, 10, ret, 5, 2);
/*     */     
/* 311 */     return ret;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public static byte[] datetimeZoneEncodeFast(byte[] dt)
/*     */   {
/* 323 */     byte[] ret = new byte[10];
/*     */     
/* 325 */     short year = Convertion.getShort(dt, 0);
/* 326 */     byte month = dt[2];
/* 327 */     byte day = dt[3];
/*     */     
/*     */ 
/* 330 */     ret[0] = dt[0];
/*     */     
/*     */ 
/* 333 */     ret[1] = ((byte)(year >> 8 | (month & 0x1) << 7));
/*     */     
/*     */ 
/* 336 */     ret[2] = ((byte)((month & 0xE) >> 1 | day << 3));
/*     */     
/* 338 */     byte hour = dt[4];
/* 339 */     byte min = dt[5];
/* 340 */     byte sec = dt[6];
/* 341 */     int msec = (0xFF & dt[7]) + ((dt[8] & 0xFF) << 8) + (
/* 342 */       (dt[9] & 0xFF) << 16);
/*     */     
/*     */ 
/* 345 */     ret[3] = ((byte)(hour | (min & 0x7) << 5));
/*     */     
/*     */ 
/* 348 */     ret[4] = ((byte)((min & 0x38) >> 3 | (sec & 0x1F) << 3));
/*     */     
/*     */ 
/* 351 */     ret[5] = ((byte)((sec & 0x20) >> 5 | (msec & 0x7F) << 1));
/*     */     
/*     */ 
/* 354 */     ret[6] = ((byte)(msec >> 7 & 0xFF));
/*     */     
/*     */ 
/* 357 */     ret[7] = ((byte)(msec >> 15 & 0xFF));
/*     */     
/* 359 */     System.arraycopy(dt, 10, ret, 8, 2);
/*     */     
/* 361 */     return ret;
/*     */   }
/*     */   
/*     */   public String toString() {
/* 365 */     return getStrFromTZ();
/*     */   }
/*     */ }


/* Location:              D:\Program Files\DBMS_20150813\jdbc\Dm7JdbcDriver17.jar!\dm\sql\DmdbTimeZone.class
 * Java compiler version: 2 (46.0)
 * JD-Core Version:       0.7.1
 */